package com.dgshanger.sanhxiaofeisc.ui.home.activity

import android.os.Build
import android.webkit.WebSettings
import android.webkit.WebView
import android.webkit.WebViewClient
import com.dgshanger.sanhxiaofeisc.R
import com.xx.baseuilibrary.mvp.BaseMvpViewActivity
import kotlinx.android.synthetic.main.activity_home_web.*


/**
 * Created by JacobHHH on 2018/4/26.
 */
class HomeWebActivity : BaseMvpViewActivity() {

    private lateinit var mWebUrl : String

    override fun getActivityLayoutId(): Int = R.layout.activity_home_web

    override fun initData() {
        mWebUrl = intent.getStringExtra("webUrl")
        initWeb()
    }

    private fun initWeb() {
        webView.requestFocus()
        webView.isHorizontalScrollBarEnabled = false
        webView.isVerticalScrollBarEnabled = false
        webView.isScrollContainer = false
        val settings = webView.settings
        settings.javaScriptEnabled = true
        settings.blockNetworkImage = false
        settings.useWideViewPort = true
        settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.SINGLE_COLUMN
        settings.layoutAlgorithm = WebSettings.LayoutAlgorithm.NARROW_COLUMNS
        settings.builtInZoomControls = true // 设置显示缩放按钮
        settings.setSupportZoom(true) // 支持缩放
        if (Build.VERSION.SDK_INT >= 21)
        //Build.VERSION_CODES.LOLLIPOP

            settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW

        webView.webViewClient = object : WebViewClient() {
            override fun shouldOverrideUrlLoading(view: WebView, url: String): Boolean {
                view.loadUrl(url)
                return true
            }
        }

        webView.loadUrl(mWebUrl)
    }

    override fun initEvent() {

    }
}